package com.kele.test.rabbitmq.service;

import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.io.IOException;

@Component
public class MQService_High5_DeadLetter {

    /**
     * @param msg
     * @param message
     * @param channel
     * @throws IOException
     */
    //@RabbitListener(queues = {"queue_dlx_business"},concurrency = "2")
    public void testRevMsg(String msg, Message message, Channel channel) throws IOException {

        System.out.println("queue_dlx_business++++++" + msg);
        String messageId = message.getMessageProperties().getMessageId();


        long deliveryTag = message.getMessageProperties().getDeliveryTag();
        System.out.println("queue_dlx_business++++++ NACK （拒收）" + msg);
        channel.basicNack(deliveryTag,false,false);//NACK
    }

    @RabbitListener(queues = {"dlx_deadletter_queue"},concurrency = "1")
    public void testDeadLetterRevMsg(String msg, Message message, Channel channel) throws IOException {

        long id = Thread.currentThread().getId();
        String messageId = message.getMessageProperties().getMessageId();
        System.out.println(Thread.currentThread().getId()+ " dlx_deadletter_queue++++++" + msg + " messageId:" + messageId);
        long deliveryTag = message.getMessageProperties().getDeliveryTag();

        channel.basicAck(deliveryTag,false);//ACK
    }
}
